﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using kinokasse.bauteile.contracts.ebcpatterns;
using NUnit.Framework;

namespace kinokasse.ebcpatterns.tests
{
    [TestFixture]
    public class test_Join
    {
        [Test]
        public void join_with_input0_first()
        {
            var sut = new Join<int, int>();

            Tuple<int, int> result = null;
            sut.Out_Joined += j => result = j;

            sut.In0(1);
            Assert.IsNull(result);
            sut.In1(2);
            Assert.AreEqual(1, result.Item1);
            Assert.AreEqual(2, result.Item2);
        }


        [Test]
        public void join_with_input1_first()
        {
            var sut = new Join<int, int>();

            Tuple<int, int> result = null;
            sut.Out_Joined += j => result = j;

            sut.In1(2);
            Assert.IsNull(result);
            sut.In0(1);
            Assert.AreEqual(1, result.Item1);
            Assert.AreEqual(2, result.Item2);
        }


        [Test]
        public void joind_is_reset_after_join()
        {
            var sut = new Join<int, int>();

            int joinCounter = 0;
            sut.Out_Joined += r => joinCounter += 1;

            sut.In0(1);
            Assert.AreEqual(0, joinCounter);
            sut.In1(2);
            Assert.AreEqual(1, joinCounter);
            sut.In0(3);
            Assert.AreEqual(1, joinCounter);
        }

    }
}
